﻿using System;
using System.Collections.Generic;
using System.IO;
using FunctionalCLR.Shell;
using Zove.Query;
using Zove.Shell.Core;

namespace Zove.Shell {
    public class ZoveConsole : ShellConsole {

        public override string Title
        {
            get
            {
                return "Zove Console";
            }
        }

        public override string WelcomeMessage
        {
            get
            {
                return "Zove Console\nCopyright 2009 Team Zove";
            }
        }

        public static void Main(string[] args) {
            ZoveConsole console = new ZoveConsole();

            console.Process(args);
        }

        protected override void Process(string fileName)
        {
            if (fileName.EndsWith(".zql"))
            {
                string source = File.ReadAllText(fileName);

                QueryManager qm = new QueryManager();
                Query.Query query = qm.CreateQuery(source);
                List<QueryResult> results = query.Run();

                Console.WriteLine("Result:");
                foreach (QueryResult r in results)
                {
                    Console.WriteLine(r);
                }
            }
            else
            {
                Console.WriteLine("Unregonised file type");
            }
        }

        protected override Interpreter GetInterpreter()
        {
            return new ZoveShellInterpreter();
        }
    }
}
